<?php
class hrd_bantuan_cuti_model extends MY_Model {
	var $nama_tabel = 'hrd_bantuan_cuti';
	
	function GetJSON() {
		$ls_sql	= "	SELECT	a.id_karyawan_fk, b.nama_karyawan, c.ket_jenis_cuti, c.lama_hari, TO_CHAR(a.tgl_mulai,'DD/MM/YYYY') tgl_mulai, a.status_bayar, TO_CHAR(a.tgl_selesai,'DD/MM/YYYY') tgl_selesai, a.status_valid, a.nilai, TO_CHAR(b.tgl_bergabung, 'DD/MM/YYYY') tgl_bergabung
					FROM	".$this->nama_tabel." A
					LEFT JOIN hrd_karyawan B on A.id_karyawan_fk = b.id_karyawan_pk
					LEFT JOIN hrd_jenis_cuti C ON A.id_jenis_cuti_fk = c.id_jenis_cuti_pk
					WHERE	(UPPER(c.ket_jenis_cuti) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(b.nama_karyawan) LIKE '%".strtoupper(post('keyword'))."%')
					AND id_periode_fk = '".post('idPeriode')."'
					ORDER BY ".(post('sort')=='' ? 'a.tgl_rekam' : post('sort'))." ".(post('order')=='' ? 'desc' : post('order'));
					
					
		return json_encode( $this->paging($ls_sql) );
					// print_r($ls_sql);
	}

	function Add($arr_data){
		$this->db->insert($this->nama_tabel, $arr_data);
	}

	function Update($arr_data, $arr_rule){
		$this->db->update($this->nama_tabel, $arr_data, $arr_rule);
	}

	function DeleteSingle($arr_rule) {
		try {
			$this->db->delete($this->nama_tabel, array('id_bantuan_cuti_pk' => $arr_rule['id_bantuan_cuti_pk']));
			return '';
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}

}
?>